const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const miniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');

module.exports = {
	entry: './src/index.js',
	output: {
		filename: './static/js/build.js',
		path: resolve(__dirname, 'build')
	},
	module: {
		rules: [
			{
				test: /\.css/,
				use: [
					// css提取成单独的文件，则不需要使用style-loader,需要使用插件
					// 'style-loader', // 创建style标签
					miniCssExtractPlugin.loader, // 创建link标签，引入样式文件
					// 将css文件整合到js中
					'css-loader'
				]
			},
			{
				test: /\.js/,
				use: 'babel-loader'
			}
		]
	},
	plugins: [
		new HtmlWebpackPlugin({
			template: './src/index.html'
		}),
		new miniCssExtractPlugin({
			// 生成的单独的css文件重命名
			filename: './css/base.css'
		}),
		new OptimizeCssAssetsPlugin({})
	],
	// mode: 'development'
	mode: 'production'
};
